﻿Imports Co9320.NamaAlert.Model
Imports System.Windows.Threading

Public Class DummyFeeder
    Implements ISystemMessageSender

#Region "Events"

    Public Event LiveProgramStarted As EventHandler(Of LiveProgramEventArgs)
    Protected Overridable Sub OnLiveProgramStarted(ByVal e As LiveProgramEventArgs)
        RaiseEvent LiveProgramStarted(Me, e)
    End Sub

    Public Event LiveProgramClosed As EventHandler(Of LiveProgramEventArgs)
    Protected Overridable Sub OnLiveProgramClosed(ByVal e As LiveProgramEventArgs)
        RaiseEvent LiveProgramClosed(Me, e)
    End Sub

    Public Event LiveProgramUpdated As EventHandler(Of LiveProgramEventArgs)
    Protected Overridable Sub OnLiveProgramUpdated(ByVal e As LiveProgramEventArgs)
        RaiseEvent LiveProgramUpdated(Me, e)
    End Sub

    Public Event SendSystemMessage(ByVal sender As Object, ByVal e As Model.SystemMessageEventArgs) Implements ISystemMessageSender.SendSystemMessage

#End Region

    Public Sub New()
        Timer.Interval = New TimeSpan(0, 0, 1)
        Timer.Start()
    End Sub

    Private WithEvents Timer As New DispatcherTimer


    Private Sub Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer.Tick

        Static i As Integer = 0

        Dim rnd = New Random
        Dim p = New LiveProgram With { _
            .Id = i, _
            .Title = "プログラム" & i.ToString, _
            .ShortContent = "紹介文" & i.ToString, _
            .CasterName = "放送者" & i.ToString, _
            .CommentCount = rnd.Next(0, 1000), _
            .VisitorCount = rnd.Next(0, 1000), _
            .CrawlingDateTime = Now, _
            .IsOnAir = True, _
            .IsMemberOnly = If(rnd.Next(0, 10) = 0, True, False), _
            .IsFace = If(rnd.Next(0, 10) = 0, True, False), _
            .StartDateTime = Now}

        With p.Station
            .Id = "co" & i.ToString
            .Name = "コミュニティ" & i.ToString
            .UpdateDateTime = Now
        End With

        i += 1
        OnLiveProgramStarted(New LiveProgramEventArgs(p))

    End Sub

End Class
